package com.lzw.common.tool;

import javax.servlet.http.HttpSession;

/**
 * 验证码的工具
 * Created by 林志伟 on 2017/6/2.
 */

public class KaptchaTool {


    private HttpSession httpSession;

    private String codeKey="check_code";

    public KaptchaTool(HttpSession httpSession){
        this.httpSession=httpSession;
    }

    public void save(String codeText){
//        System.out.println("验证码key:"+this.codeKey);
        this.httpSession.setAttribute(this.codeKey,codeText);
    }
    public String  get(){
       return (String) this.httpSession.getAttribute(this.codeKey);
    }
    public void remove(){
        this.httpSession.removeAttribute(this.codeKey);
    }
    public boolean check(String codeText){
        String sessioncode=this.get();
        if(sessioncode==null||!sessioncode.equals(codeText)){
            return  false;
        }else
            return  true;
    }
}
